#ifndef _FPDF_EMB_DOCSAVER_H_
#define _FPDF_EMB_DOCSAVER_H_

#ifdef __cplusplus
extern "C" {
#endif

/********************************************************************************************
****
****		Document Operations
****
********************************************************************************************/

/**
 * @brief  Structure: FPDFEMB_FILEWRITE_ACCESS
 *			Describe the way to access a file (writeonly).
 */
struct FPDFEMB_FILEWRITE_ACCESS {
	/**
	 * Interface: GetSize
	 *		Get current size of the file
	 *
	 * @param[in] file			Pointer to this file access structure
	 * @return File size, in bytes. Implementation can return -1 for any error.
	 */
	unsigned int	(*GetSize)(struct FPDFEMB_FILEWRITE_ACCESS* file);

	/**
	 * Interface: WriteBlock
	 *		Write a data block to the file
	 *
	 * @param[in] file			Pointer to this file access structure
	 * @param[in] buffer		Pointer to a buffer containing write data
	 * @param[in] offset		Byte offset for the block, from beginning of the file
	 * @param[in] size			Number of bytes for the block.
	 * @return Error code, or FPDFERR_SUCCESS for success.
	 */
	FPDFEMB_RESULT	(*WriteBlock)(struct FPDFEMB_FILEWRITE_ACCESS* file, const void* buffer,
									unsigned int offset, unsigned int size);
	/**
	 * Interface: Flush
	 *		Flushes a stream
	 *
	 * @param[in] file			Pointer to this file access structure
	 * @return Error code, or FPDFERR_SUCCESS for success.
	 */
	FPDFEMB_RESULT	(*Flush)(struct FPDFEMB_FILEWRITE_ACCESS* file);

	void*		user;		/**< A user pointer, used by the application. */
};

/**
 * @name Saving flags for save document.
 */
/*@{*/

/** @brief Incremental. */
#define FPDFEMB_SAVEAS_INCREMENTAL		1
/** @brief No original. */
#define FPDFEMB_SAVEAS_NOORIGINAL		2

/**
 * Function: FPDFEMB_StartSaveDocumentAs
 *			Save the modified document to a new file
 *
 * @param[in] document		Document handle 
 * @param[in] file			Pointer to file access structure.
 * @param[in] flag			The saving flags. See the above FPDFEMB_SAVEAS_xxx definitions
 * @param[in] pause			A callback mechanism allowing the document loading process
 *							to be paused before it's finished. This can be NULL if you
 *							don't want to pause.
 * @return Error code. FPDFERR_SUCCESS for success.
 */
FPDFEMB_RESULT FPDFEMB_StartSaveDocumentAs(FPDFEMB_DOCUMENT document, struct FPDFEMB_FILEWRITE_ACCESS* file,
										   int flag, struct FPDFEMB_PAUSE* pause);

/**
 * Function: FPDFEMB_ContinueSaveDocumentAs
 *			Continue saving a PDF document
 *
 * @param[in] document		Document handle returned by FPDFEMB_StartLoadDocument function
 * @param[in] pause			A callback mechanism allowing the document loading process
 *							to be paused before it's finished. This can be NULL if you
 *							don't want to pause.
 * @return Error code. FPDFERR_SUCCESS for success.
 */
FPDFEMB_RESULT FPDFEMB_ContinueSaveDocumentAs(FPDFEMB_DOCUMENT document, struct FPDFEMB_PAUSE* pause);

/**
 * Function: FPDFEMB_StartReloadDocument
 *			Reload a document after it is modified 
 *
 * Comments:
 *			Document reloading is a progressive process. It might take a long time to
 *			reload the document. If "pause" parameter is provided, this function may 
 *			return FPDFERR_TOBECONTINUED any time during the document loading.
 *
 * @param[in] document		Document handle 
 * @param[in] file			Pointer to file access structure.
 *							This structure must be kept valid before next reloading.
 * @param[in] password		Pointer to a zero-terminated byte string, for the password.
 *							Or NULL for no password.
 * @param[in] pause			A callback mechanism allowing the document loading process
 *							to be paused before it's finished. This can be NULL if you
 *							don't want to pause.
 * @return Error code. FPDFERR_SUCCESS for success.
 */
FPDFEMB_RESULT FPDFEMB_StartReloadDocument(FPDFEMB_DOCUMENT document, struct FPDFEMB_FILE_ACCESS* file, 
										   const char* password, struct FPDFEMB_PAUSE* pause);

/**
 * Function: FPDFEMB_ContinueLoadDocument
 *			Continue reloading a PDF document
 *
 * @param[in] document		Document handle returned by FPDFEMB_StartLoadDocument function
 * @param[in] pause			A callback mechanism allowing the document loading process
 *							to be paused before it's finished. This can be NULL if you
 *							don't want to pause.
 * @return Error code. FPDFERR_SUCCESS for success.
 */
FPDFEMB_RESULT FPDFEMB_ContinueReloadDocument(FPDFEMB_DOCUMENT document, struct FPDFEMB_PAUSE* pause);

/**
 * @name Document Permissions for FPDFEMB SDK
 */
/*@{*/

/** @brief Set if the user is not allowed to print. */
#define FPDFEMB_PERMISSION_PRINT			0x0004
/** @brief Set if the user is not allowed to modify. */
#define FPDFEMB_PERMISSION_MODIFY			0x0008
/** @brief Set if the user is not allowed to extract content. */
#define FPDFEMB_PERMISSION_EXTRACT			0x0010
/** @brief Set if the user is not allowed to annotate. */
#define FPDFEMB_PERMISSION_ANNOTFORM		0x0020
/** @brief Set if the user is not allowed to modify form field data. */
#define FPDFEMB_PERMISSION_FILLFORM			0x0100
/** @brief Set if the user is not allowed to extract content. */
#define FPDFEMB_PERMISSION_EXTRACTACCESS	0x0200
/** @brief Set if the user is not allowed to organize the document. */
#define FPDFEMB_PERMISSION_ASSEMBLE			0x0400
/** @brief Set if the user is not allowed to print at highest quality. */
#define FPDFEMB_PERMISSION_PRINT_HIGH		0x0800

/**
 * Function: FPDFEMB_GetDocumentPermissions
 *			Get permission flags specified by a PDF document
 *
 * @param[in] document		Document handle returned by FPDFEMB_StartLoadDocument function
 *
 * @return permission flag. See FPDFEMB_PERMISSIONs defined above.
 *                          Document permissions are set bitwise in the return value.
 */
unsigned int FPDFEMB_GetDocumentPermissions(FPDFEMB_DOCUMENT document);

/**
 * Function: FPDFEMB_AddDocumentModifyMark
 *			Add some mark string on the special page.
 *			Only English text string is supported for now.
 *
 * @param[in] document		Document handle returned by FPDFEMB_StartLoadDocument function
 * @param[in] page			Page handle
 * @param[in] x				X position in PDF page coordination system, in hundredth of points
 * @param[in] y				Y position in PDF page coordination system, in hundredth of points
 * @param[in] fontsize		font size used to write string
 * @param[in] string		text string to write on the page
 *
 * @return Error code. FPDFERR_SUCCESS for success.
 */
FPDFEMB_RESULT FPDFEMB_AddDocumentModifyMark(FPDFEMB_DOCUMENT document, FPDFEMB_PAGE page, 
											 int x, int y, int fontsize, char* string);

#ifdef __cplusplus
}
#endif

#endif // _FPDF_EMB_DOCSAVER_H_